using System;
using System.Collections.Generic;
using UnityEngine;

public class RankConversion : ScriptableObject
{
	[Serializable]
	public class Mapping
	{
		public int oldRank;

		public List<int> subranks;
	}

	protected static RankConversion instance_;

	public List<Mapping> map = new List<Mapping>();

	public static RankConversion instance
	{
		get
		{
			if (instance_ == null)
			{
				instance_ = Resources.Load("RankConversion", typeof(RankConversion)) as RankConversion;
			}
			return instance_;
		}
	}

	private Mapping FindNewMapping(int oldRank)
	{
		foreach (Mapping item in map)
		{
			if (item.oldRank == oldRank)
			{
				return item;
			}
		}
		return null;
	}

	private Mapping FindOldMapping(int newLevel)
	{
		for (int num = map.Count - 1; num >= 0; num--)
		{
			Mapping mapping = map[num];
			if (mapping.subranks.Count > 0 && mapping.subranks[0] <= newLevel)
			{
				return mapping;
			}
		}
		return null;
	}

	public int FindNewRank(int oldRank, float oldProgress)
	{
		Mapping mapping = FindNewMapping(oldRank);
		if (mapping == null)
		{
			return 0;
		}
		int count = mapping.subranks.Count;
		if (count == 0)
		{
			return 0;
		}
		for (int num = count - 1; num > 0; num--)
		{
			if (oldProgress >= (float)num / (float)count)
			{
				return mapping.subranks[num];
			}
		}
		return mapping.subranks[0];
	}

	public int FindOldRank(int newLevel)
	{
		Mapping mapping = FindOldMapping(newLevel);
		if (mapping == null)
		{
			return 0;
		}
		return mapping.oldRank;
	}
}
